// XFAIL: *
// RUN: %amp_device -c -D__KALMAR_ACCELERATOR__=1 -S -emit-llvm %s -o -|%cppfilt|%FileCheck %s
// RUN: %amp_device -c -D__KALMAR_ACCELERATOR__=1 %s -o %t.device.o
// RUN: %gtest_amp %s %t.device.o -o %t && %t
#ifndef __KALMAR_ACCELERATOR__
#include <gtest/gtest.h>
#endif
class base{
 public:
  __attribute__((annotate("deserialize"))) /* For compiler */
  base(int a_,float b_) restrict(amp) :a(a_), b(b_) {}
  int a;
  float b;
};
class baz {
 public:
#if 0 // This declaration is supposed to be generated
  __attribute__((annotate("deserialize"))) /* For compiler */
  baz(base&, int foo) restrict(amp);
#endif
  void cho(void) restrict(amp) {};

  base &B; // No reference type is considered amp-compatible
  int bar;
};

#ifdef __KALMAR_ACCELERATOR__
int kerker(void) restrict(amp,cpu) {
  base b(1234, 0.0f);
  // Will pass if deserializer declaration and definition are generated
  baz bl(b, 1);
  return bl.B.a;
}
#else
extern int kerker(void) restrict(amp,cpu);
TEST(GPUCodeGen, ConstructorWithRef) {
  EXPECT_EQ(kerker(), 1234);
}
#endif
// The definition should be generated by clang
// CHECK: define {{.*}}void @baz::baz(base&, int)(
